package com.bupt.ilink.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bupt.ilink.entity.DatasetMetadata;
import com.bupt.ilink.entity.ModelMetadata;
import com.bupt.ilink.service.ModelMetadataService;
import com.bupt.ilink.mapper.ModelMetadataMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* @author LENOVO
* @description 针对表【model_metadata】的数据库操作Service实现
* @createDate 2024-08-03 13:02:58
*/
@Service
public class ModelMetadataServiceImpl extends ServiceImpl<ModelMetadataMapper, ModelMetadata>
    implements ModelMetadataService{
    @Autowired
    private ModelMetadataMapper modelMetadataMapper;
    @Override
    public Set<String> getAllNames() {
        List<String> modelNames = modelMetadataMapper.getAllNames();
        return new HashSet<>(modelNames);
    }

    @Override
    public IPage<ModelMetadata> getAllModelsByPage(Page<ModelMetadata> page) {
        return lambdaQuery().page(page);
    }
    @Override
    public IPage<ModelMetadata> getModelsByKeywords(Page<ModelMetadata> pageRequest, String keywords) {
        QueryWrapper<ModelMetadata> queryWrapper = new QueryWrapper<>();
        if (keywords != null && !keywords.isEmpty()) {
            queryWrapper.lambda().like(ModelMetadata::getModelName, keywords);
        }
        return modelMetadataMapper.selectPage(pageRequest, queryWrapper);
    }
    @Override
    public IPage<ModelMetadata> getModelsByTag(Page<ModelMetadata> pageRequest, String tag) {
        QueryWrapper<ModelMetadata> queryWrapper = new QueryWrapper<>();
        if (tag != null && !tag.isEmpty()) {
            queryWrapper.lambda().like(ModelMetadata::getBelong, tag);
        }
        return modelMetadataMapper.selectPage(pageRequest, queryWrapper);
    }

    @Override
    public IPage<ModelMetadata> getModelsByKeywordsAndTag(Page<ModelMetadata> pageRequest, String keywords, String tag) {
        QueryWrapper<ModelMetadata> queryWrapper = new QueryWrapper<>();
        if (keywords != null && !keywords.isEmpty() && tag != null && !tag.isEmpty()) {
            queryWrapper.lambda().like(ModelMetadata::getModelName, keywords)
                    .and(wrapper -> wrapper.like(ModelMetadata::getBelong, tag));
        }
        return modelMetadataMapper.selectPage(pageRequest, queryWrapper);
    }

    @Override
    public ModelMetadata selectById(String targetId){
        return modelMetadataMapper.selectById(targetId);
    }
}




